<?
require("config.php");

$label = "Product List";

$table="pro_basic";

if ($action=="search"){


	$Query="SELECT 
	id,
	name,
	code,
	stock,
	reorder,
	category

	FROM $table WHERE 

	code		LIKE '%$Code%'		AND 
	name		LIKE '%$Name%'		AND
	category	LIKE '%$Category%' 
	ORDER BY id DESC";

	$re=myQuery($Query);

}else{

	$Query="SELECT 
	id,
	name,
	code,
	stock,
	reorder,
	category
	FROM $table ORDER BY  code";

	$re=myQuery($Query);

}


require($rela_path . "inc/header1.php");
?>
      <br>




      <table width="90%" border="0" align="center">
        <tr> 
          <td>
		  
		  
		  
		  
		  
<FORM METHOD=get ACTION="">		  
		  
<input name="action" type="hidden" value="search">
		  
		  <table border="0">
              <tr> 
                <td><strong>Search by </strong></td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td>Product Code :</td>
                <td><input type="text" class="text" name="Code"></td>
              </tr>
              <tr> 
                <td>Product Name :</td>
                <td><input type="text" class="text" name="Name"></td>
              </tr>
              <tr> 
                <td>Category :</td>
                <td>
<?
$boxName="Category";

$tb = "pro_category";

$Query = "select name from $tb WHERE level=0 order by id";
$r = myQuery($Query);

$Query = "select name, parent from $tb WHERE level=1 order by id";
$r1 = myQuery($Query);

$Query = "select name, parent from $tb WHERE level=2 order by id";
$r2 = myQuery($Query);

$sourceData = array();
$sourceLabel = array();

for ($i=0;$i<count($r);$i++){

	array_push($sourceData,$r[$i][0]);
	array_push($sourceLabel,$r[$i][0]);

	for ($n=0;$n<count($r1);$n++){

		if ($r[$i][0]==$r1[$n][1]){

			array_push($sourceData,$r1[$n][0]);
			array_push($sourceLabel,"-&nbsp;&nbsp;&nbsp;" . $r1[$n][0] );

			for ($m=0;$m<count($r2);$m++){

			if ($r1[$n][0]==$r2[$m][1]){

				array_push($sourceData,$r2[$m][0]);
				array_push($sourceLabel,"---&nbsp;&nbsp;&nbsp;" . $r2[$m][0] );

			}
			}

		}
	}

}

FFPSelectBox($boxName,$Category,$sourceData,$sourceLabel);
?>
				  
				  </td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
                <td><input type="submit" class="button" name="Submit2" value="  Go  "></td>
              </tr>
            </table>
			
	</FORM>		
			
			</td>
        </tr>
      </table>
      <br>






      
<table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" class="tb">
  <tr class="tbheader"> 
    <td width="25%"> <div align="center">Product Name</div></td>
    <td width="25%"> <div align="center">Product Code</div></td>
    <td width="25%"> <div align="center">Current Stock Level</div></td>
    <td width="25%"> <div align="center">Reorder Level</div></td>
    <td width="25%"> <div align="center">Category</div></td>
  </tr>

<?if ($re){
	for ($i=0;$i<count($re);$i++){?>
  <tr class="tbcontent1"> 
    <td>
	<?print($re[$i][1])?>	
	</td>
    <td><?print($re[$i][2])?></td>
    <td> <div align="center"><?print($re[$i][3])?></div></td>
    <td> <div align="center"><?print($re[$i][4])?></div></td>
    <td> <div align="center"><?=$re[$i][5]?></div></td>
  </tr>
<?}
}?>


</table>

      <p>&nbsp;</p>
      <p>&nbsp;</p>
<?
require($rela_path . "inc/footer1.php");
?>
